package com.tianqu.tms.www.car.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.www.car.controller.CarGatesInfoIOResultController;
import com.tianqu.tms.www.car.controller.CarInnerListTopController;
import com.tianqu.tms.www.car.viewhelper.CarGatesInfoIOViewhelper;
/**
 * 车辆进出库查询结果页面Action
 * 
 * @author tianshifu
 *
 */
public class CarGatesInfoIOResultAction extends TmsAction {

	private Logger logger = Logger.getLogger(CarGatesInfoIOResultAction.class);
	
	public final static String PAGENO = "pageNo";
	public final static String SORTKEY = "sortKey";
	public final static String MAXINDEX = "maxIndex";
	public final static String ASC = "asc";
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		CarGatesInfoIOViewhelper view = new CarGatesInfoIOViewhelper();
			if(request.getParameter(PAGENO) == null) {
				uc.setAttribute(PAGENO, view.getPageNo());
				uc.setAttribute(SORTKEY, view.getSortKey());
				uc.setAttribute(MAXINDEX, view.getMaxIndex());
				uc.setAttribute(ASC, view.getAsc());
			} else {
				uc.setAttribute(PAGENO, request.getParameter(PAGENO));
				uc.setAttribute(SORTKEY, request.getParameter(SORTKEY));
				uc.setAttribute(MAXINDEX, request.getParameter(MAXINDEX));
				uc.setAttribute(ASC, request.getParameter(ASC));
			}		
		
		CarGatesInfoIOResultController controller = new CarGatesInfoIOResultController();
		controller.execute(uc);

		view.setSearchResultList((List)uc.getAttribute(TmsConstants.VIEWHELP));
		Car car = (Car)uc.getAttribute(CarGatesInfoIOResultController.PAGING);
		
		// viewhelp中设置翻页。
		view.setPageNo(Integer.toString(car.getPageNo()));
		view.setMaxIndex(Integer.toString(car.getMaxIndex()));
		view.setAsc(Boolean.toString(car.isAsc()));
		view.setSortKey(Integer.toString(car.getSortKey()));
		view.setTotalCount(Integer.toString(car.getTotalCount()));
		view.setDateFrom(Integer.toString(car.getDateFrom()));
		view.setDateTo(Integer.toString(car.getDateTo()));
		
		
		request.setAttribute(TmsConstants.VIEWHELP, view);		
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
